package com.geekchique.runningbuddy.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.Menu.Item;
import android.widget.Button;
import android.widget.TableLayout;
import android.widget.TextView;

import com.geekchique.runningbuddy.R;
import com.geekchique.runningbuddy.controller.IOptionsMenu;
import com.geekchique.runningbuddy.controller.IPastJogsController;
import com.geekchique.runningbuddy.controller.OptionsMenuImpl;
import com.geekchique.runningbuddy.controller.PastJogsControllerImpl;
import com.geekchique.runningbuddy.service.PastJogsCalendar;

public class PastJogs extends Activity {
	
	private IPastJogsController pastJogsController;
	private IOptionsMenu optionsMenu;
	
	@Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.calendar);
		optionsMenu = new OptionsMenuImpl(this);

        pastJogsController = new PastJogsControllerImpl();
        pastJogsController.createControls(this, 
        		this,
        		(Button) findViewById(R.id.goto_today),
				(TextView) findViewById(R.id.cal_month),
				(Button) findViewById(R.id.btn_context_day),
				(Button) findViewById(R.id.btn_context_month),
				(Button) findViewById(R.id.btn_context_year),
				(Button) findViewById(R.id.btn_backPeriod),
				(Button) findViewById(R.id.btn_forwardPeriod));
        
        pastJogsController.createCalendar(
        		(TableLayout) findViewById(R.id.jogcalendar), 
				(Button) findViewById(R.id.cal_00),
				(Button) findViewById(R.id.cal_01),
				(Button) findViewById(R.id.cal_02),
				(Button) findViewById(R.id.cal_03),
				(Button) findViewById(R.id.cal_04),
				(Button) findViewById(R.id.cal_05),
        		(Button) findViewById(R.id.cal_06),
        		(Button) findViewById(R.id.cal_10),
        		(Button) findViewById(R.id.cal_11),
        		(Button) findViewById(R.id.cal_12),
        		(Button) findViewById(R.id.cal_13),
        		(Button) findViewById(R.id.cal_14),
        		(Button) findViewById(R.id.cal_15),
        		(Button) findViewById(R.id.cal_16),
        		(Button) findViewById(R.id.cal_20),
        		(Button) findViewById(R.id.cal_21),
        		(Button) findViewById(R.id.cal_22),
        		(Button) findViewById(R.id.cal_23),
        		(Button) findViewById(R.id.cal_24),
        		(Button) findViewById(R.id.cal_25),
        		(Button) findViewById(R.id.cal_26),
        		(Button) findViewById(R.id.cal_30),
        		(Button) findViewById(R.id.cal_31),
        		(Button) findViewById(R.id.cal_32),
        		(Button) findViewById(R.id.cal_33),
        		(Button) findViewById(R.id.cal_34),
        		(Button) findViewById(R.id.cal_35),
        		(Button) findViewById(R.id.cal_36),
        		(Button) findViewById(R.id.cal_40),
        		(Button) findViewById(R.id.cal_41),
        		(Button) findViewById(R.id.cal_42),
        		(Button) findViewById(R.id.cal_43),
        		(Button) findViewById(R.id.cal_44),
        		(Button) findViewById(R.id.cal_45),
        		(Button) findViewById(R.id.cal_46),
        		(Button) findViewById(R.id.cal_50),
        		(Button) findViewById(R.id.cal_51),
        		(Button) findViewById(R.id.cal_52),
        		(Button) findViewById(R.id.cal_53),
        		(Button) findViewById(R.id.cal_54),
        		(Button) findViewById(R.id.cal_55),
        		(Button) findViewById(R.id.cal_56));
        
				startCalendarService();
    }

	public void startCalendarService() {
		startService(new Intent(PastJogs.this, PastJogsCalendar.class), null);		
	}
	
	public void stopCalendarService() {
		stopService(new Intent(PastJogs.this, PastJogsCalendar.class));		
	}
	
    @Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		optionsMenu.addAllActivitiesToMenu(menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(Item item) {
		optionsMenu.selectItem(item);
	    return super.onOptionsItemSelected(item);
	}
}
